<?php

namespace AdminBundle\Repository;


class HuobiMarketKline30minRepository extends BaseRepository
{
    const UNIT = 1800; // 30*60
    public function get60mins($coin, $timestamp = 0, $duration = 60)
    {
        $sql = <<<EOF
select 
	coin_open as `open`,
	coin_close as `close`,
	coin_low as `low`,
	coin_high as `high`,
	coin_amount as `amount`,
	coin_vol as `vol`,
	coin_count as `count`,
	DATE_FORMAT(coin_time,'%Y-%m-%d %H:%i:%s') as `time`,
	time_stamp as `time_stamp`,
	k_5mins, d_5mins, k_10mins, d_10mins,
	rsi_5mins, rsi_10mins, rsi_20mins, rsi_30mins
from 
  huobi_market_kline_30min 
where
  coin = :coin 
  and time_stamp > :time_stamp60 
  and time_stamp <= :time_stamp
  
order by id desc 
EOF;

        $timestamp = $timestamp ?: time();

        $params = ['coin' => $coin, 'time_stamp' => $timestamp, 'time_stamp60' => $timestamp - self::UNIT * $duration];

        return $this->rawQuery($sql, $params);
    }

}
